package com.menu.Controller;

import com.menu.Service.MenuFatherService;
import com.menu.Service.MenuService;
import com.menu.Service.UserService;
import com.menu.Utils.RedisUtil;
import com.menu.Utils.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@Api(tags = "搜索接口")
public class SearchController {
    @Resource
    MenuService menuService;
    @Resource
    UserService userService;
    @Resource
    MenuFatherService menuFatherService;

    @ApiOperation(value = "搜索食谱--前台(搜索审核通过的食谱)")
    @GetMapping("/Visitor/findMenuByNameLike")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "pageNow", value = "当前页数", required = true),
                    @ApiImplicitParam(name = "pageSize", value = "一页几条", required = true),
                    @ApiImplicitParam(name = "key", value = "关键词", required = true)
            }
    )
    public ResponseResult findMenuByNameLike(String key,Integer pageNow, Integer pageSize){
        return menuService.findMenuByNameLike(key,pageNow, pageSize);
    }


    @ApiOperation(value = "搜索食谱--后台")
    @GetMapping("/Admin/adminFindMenuByNameLike")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "pageNow", value = "当前页数", required = true),
                    @ApiImplicitParam(name = "pageSize", value = "一页几条", required = true),
                    @ApiImplicitParam(name = "key", value = "关键词", required = true)
            }
    )
    public ResponseResult adminFindMenuByNameLike(String key,Integer pageNow, Integer pageSize){
        return menuService.adminFindMenuByNameLike(key,pageNow, pageSize);
    }


    @ApiOperation(value = "搜索菜单--前台(搜索审核通过的菜单)")
    @GetMapping("/Visitor/findMenuFatherByNameLike")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "pageNow", value = "当前页数", required = true),
                    @ApiImplicitParam(name = "pageSize", value = "一页几条", required = true),
                    @ApiImplicitParam(name = "key", value = "关键词", required = true)
            }
    )
    public ResponseResult findMenuFatherByNameLike(String key,Integer pageNow, Integer pageSize){
        return menuFatherService.findMenuFatherByNameLike(key,pageNow, pageSize);
    }

    @ApiOperation(value = "搜索菜单--后台")
    @GetMapping("/Admin/adminFindMenuFatherByNameLike")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "pageNow", value = "当前页数", required = true),
                    @ApiImplicitParam(name = "pageSize", value = "一页几条", required = true),
                    @ApiImplicitParam(name = "key", value = "关键词", required = true)
            }
    )
    public ResponseResult adminFindMenuFatherByNameLike(String key,Integer pageNow, Integer pageSize){
        return menuFatherService.adminFindMenuFatherByNameLike(key,pageNow, pageSize);
    }


    @ApiOperation(value = "搜索用户")
    @GetMapping("/Visitor/findUserByNameLike")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "pageNow", value = "当前页数", required = true),
                    @ApiImplicitParam(name = "pageSize", value = "一页几条", required = true),
                    @ApiImplicitParam(name = "key", value = "关键词", required = true)
            }
    )
    public ResponseResult findUserByNameLike(String key,Integer pageNow, Integer pageSize){
        return userService.findUserByNameLike(key,pageNow, pageSize);
    }


    @ApiOperation(value = "搜索食谱---收藏最多--前台(搜索审核通过的食谱)")
    @GetMapping("/Visitor/findAllMenuByCollectionNameLike")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "pageNow", value = "当前页数", required = true),
                    @ApiImplicitParam(name = "pageSize", value = "一页几条", required = true),
                    @ApiImplicitParam(name = "key", value = "关键词", required = true)
            }
    )
    public ResponseResult findAllMenuByCollectionNameLike(String key,Integer pageNow, Integer pageSize){
        return menuService.findAllMenuByCollectionNameLike(key,pageNow, pageSize);
    }



    @ApiOperation(value = "搜索食谱---浏览量最多--前台(搜索审核通过的食谱)")
    @GetMapping("/Visitor/findAllMenuByDohNameLike")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "pageNow", value = "当前页数", required = true),
                    @ApiImplicitParam(name = "pageSize", value = "一页几条", required = true),
                    @ApiImplicitParam(name = "key", value = "关键词", required = true)
            }
    )
    public ResponseResult findAllMenuByDohNameLike(String key,Integer pageNow, Integer pageSize){
        return menuService.findAllMenuByDohNameLike(key,pageNow, pageSize);
    }

    @ApiOperation(value = "根据id搜索用户信息")
    @GetMapping("/Visitor/findByUserId")
    public ResponseResult findByUserId(Integer userId){
        if (userId == null){
            return ResponseResult.error("参数有误！");
        }
        return userService.findByUserId(userId);
    }
}
